var app = angular.module('app', ['ngRoute'])
    .config(function ($routeProvider){
        $routeProvider
            .when('/other', {
                controller: 'otherCtrl',
                templateUrl: 'error.html',
                publicAccess: true
            })
            .when('/', {
                controller: 'homeCtrl',
                templateUrl: 'content.html'
            })
            .otherwise({
                redirectTo: '/'
            });
    });

app.controller('homeCtrl',function($scope,$http){
    console.log('i am home page');
    $scope.title = 'i am home page';
}).controller('otherCtrl',function($scope){
    console.log('i am other page');
    $scope.title = 'i am other page';
}).controller('otherDetailCtrl',function($scope, $routeParams, $location){
    var id = $routeParams.id;
    if(id == 0) {
        $location.path('/other');
    }
    console.log('i am otherDetailCtrl page');
    $scope.title = 'i am otherDetailCtrl page';
});

//filter  相当于自定义函数
app.filter("myup",function(){
    return function (input){
        return input.toUpperCase();
    }
});

//directive 可以在标签中自定义属性
app.directive("mydir",function(){
    return function (scope, element, attrs){
        element.bind("mouseenter", function() {
            element.css("background", "yellow");
        });
        element.bind("mouseleave", function() {
            element.css("background", "red");
        });
    }
}).directive("ehello",function(){
    return {
        restrict: 'E',
        template: '<h3>this is element</h3>',
        replace:false
    }
}).directive("ahello",function(){
    return {
        restrict: 'A',
        template: '<h3>this is attr</h3>',
        replace:true
    }
}).directive("chello",function(){
    return {
        restrict:'C',
        template:'<h3>this <span ng-transclude></span> is class</h3>',
        replace:true,
        transclude:true
    }
})